package com.duang.framework.config;

import java.util.ArrayList;
import java.util.List;

import com.duang.framework.dao.BaseDao;
import com.duang.framework.service.BaseService;

public class ServiceComponent {

	private Class<? extends BaseDao<?>> daoInterface;
	private Class<? extends BaseDao<?>> daoImplClazz;
	private String serviceName;
	private String daoName;
	private Class<? extends BaseService<?>> serviceInterface;
	private Class<? extends BaseService<?>> serviceImplClazz;
	private static List<ServiceComponent> serviceList = new ArrayList<ServiceComponent>();

	public static List<ServiceComponent> getAndSetNullServcieList() {
		List<ServiceComponent> services = serviceList;
		serviceList = null;
		return services;
	}

	public static void register(String serviceName,
			Class<? extends BaseService<?>> service, String daoName,
			Class<? extends BaseDao<?>> dao) {
		ServiceComponent serviceComponent = new ServiceComponent();
		serviceComponent.setServiceName(serviceName);
		serviceComponent.setServiceImplClazz(service);
		serviceComponent.setDaoImplClazz(dao);
		serviceComponent.setDaoName(daoName);
		serviceList.add(serviceComponent);
	}

	@Override
	public int hashCode() {
		int result = 1;
		result = 31 * result + serviceName.hashCode();
		result = 31 * result + daoName.hashCode();
		return result;
	}

	@Override
	public boolean equals(Object object) {
		if (!(object instanceof ServiceComponent)) {
			return false;
		}
		ServiceComponent service = (ServiceComponent) object;
		return this.daoName == service.daoName
				&& this.serviceName == service.serviceName;
	}

	public String getServiceName() {
		return serviceName;
	}

	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}

	public String getDaoName() {
		return daoName;
	}

	public void setDaoName(String daoName) {
		this.daoName = daoName;
	}

	public Class<? extends BaseService<?>> getServiceImplClazz() {
		return serviceImplClazz;
	}

	public void setServiceImplClazz(
			Class<? extends BaseService<?>> serviceImplClazz) {
		this.serviceImplClazz = serviceImplClazz;
	}

	public void setDaoImplClazz(Class<? extends BaseDao<?>> daoClazz) {
		this.daoImplClazz = daoClazz;
	}

	public Class<? extends BaseDao<?>> getDaoImplClazz() {
		return daoImplClazz;
	}

	public Class<? extends BaseDao<?>> getDaoInterface() {
		return daoInterface;
	}

	public void setDaoInterface(Class<? extends BaseDao<?>> daoInterface) {
		this.daoInterface = daoInterface;
	}

	public Class<? extends BaseService<?>> getServiceInterface() {
		return serviceInterface;
	}

	public void setServiceInterface(
			Class<? extends BaseService<?>> serviceInterface) {
		this.serviceInterface = serviceInterface;
	}

}
